<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 *
 *
 *
 * @package     h
 * @subpackage  models
 * @category    models
 * @author      hyw
 * @copyright   copyright (c) 2012
 * @filesource
 */
class Sms_model extends Base_model {

    protected $_table_name = 'sms';
    protected $_key_name = 'sms_id';
	
	function get_info($id) {
		if(!empty($id))
			$where[$this->_key_name]=$id;
		$where['dtime']=0;
		return $this->fetch(NULL, $where,NULL,'row');
	}

	function get_all() {
		$where=array("dtime"=>0);
		return $this->fetch(NULL, $where);
    }

	 function get_sms($where,$limit) {
		$this->set_order_by('ctime,DESC');
		$this->set_limit($limit);
		$where=array('dtime'=>0);
		return $this->fetch(NULL, $where);
    }
	function get_sms_count($uri_query) {
		$con["where"][] = array('dtime'=>0);
        $this->set_args_array($con);
        return $this->fetch_count();
	}
	function update_data($data) {
		$value=array('to'=>$data['to'],'content'=>$data['content'],'status'=>$data['status'],'mtime'=>time());
		$where[]=array($this->_key_name=>$data['id']);
		return $this->update($value, $where);
	}

	function update_status($data) {
		$value=array('status'=>$data['status'],'mtime'=>time());
		$where[]=array($this->_key_name=>$data['id']);
		return $this->update($value, $where);
	}

	function add($data) {		
		$data['ctime']=time();
		return $this->insert ( $data );
	}


	function insert($data) {		

		$data['ctime']=time();
		$this->db->insert( "h_sms" , $data );


		$this->db->where('ctime',$data['ctime']);
		$result=$this->db->get( "h_sms"  );

		$re=$result->row();

		return $re->sms_id;

	}

	function update_ok($id ,$msg) {		

		
		$data=array('return_msg'=>$msg);
		$this->db->where('sms_id',$id);
		$this->db->update($data);


	}


	function del($data) {
		$where[]=array($this->_key_name=>$data['id']);
		$value=array('dtime'=>time());
		return $this->update($value, $where);
	}
	
	
	
	
}